#!/usr/bin/python
#lancer et fermer fg avec une seule touche
#avec vlc mode daemon
# kill les log du fichier pref



import os

#recuperation des preferences
f = open('./configfg','r')
t = f.readline()

f.readline()
log1 = f.readline()
f.readline()
log2 = f.readline()
f.readline()
log3 = f.readline()
f.readline()
log4 = f.readline()
f.readline()
log5 = f.readline()
f.readline()
f.readline()
fg_url = f.readline()
#fin de la recuperation des preferences


def start_fg():
	""" start fg with vlc deamon """
	os.popen("vlc --daemon "+fg_url)

def stop_fg():
	"""kill vlc"""
	os.popen("killall vlc")

def kil_log1():
	"""kill log 1"""
	os.popen("killall "+log1)
	
def kil_log2():
	"""kill log 2"""
	os.popen("killall "+log2)

def kil_log3():
	"""kill log 3"""
	os.popen("killall "+log3)

def kil_log4():
	"""kill log 4"""
	os.popen("killall "+log4)

def kil_log5():
	"""kill log 5"""
	os.popen("killall "+log5)		
		

# recuperation des processus	
fgtest = os.popen("ps -e | grep vlc").read() 
tlog1 = os.popen("ps -e | grep "+log1).read()
tlog2 = os.popen("ps -e | grep "+log2).read()
tlog3 = os.popen("ps -e | grep "+log3).read()
tlog4 = os.popen("ps -e | grep "+log4).read()
tlog5 = os.popen("ps -e | grep "+log5).read()

if fgtest != '':
	stop_fg()
else :
	if tlog1 != '':
		kil_log1()	
	if tlog2 != '':
		kil_log2()
	if tlog3 != '':
		kil_log3()
	if tlog4 != '':
		kil_log4()
	if tlog5 != '':
		kil_log5()
	start_fg()

